/*
* ============================================================================
*  Name     : CLogExampleLogDatabaseObserver from LogExampleLogDatabaseObserver.h
*  Part of  : LogExample
*  Created  : 26.05.2005 by Forum Nokia  
*  Implementation notes:
*  Version  : 1.0
*  Copyright: Nokia Corporation
* ============================================================================*/

// INCLUDE FILES
#include "LogExampleLogDatabaseObserver.h"
#include "DatabaseObserver.h"

// ========================= PUBLIC ========================= 

// ----------------------------------------------------------
// CLogExampleLogDatabaseObserver::
// CLogExampleLogDatabaseObserver():CActive(EPriorityStandard)
// Default Symbian constructor
// ----------------------------------------------------------
//
CLogExampleLogDatabaseObserver::CLogExampleLogDatabaseObserver(MDatabaseObserver& aObserver):
			CActive(EPriorityStandard), iObserver(aObserver)
	{
	}

// ----------------------------------------------------
// CLogExampleLogDatabaseObserver::~CLogExampleLogDatabaseObserver()
// Destructor
// Frees reserved resources
// ----------------------------------------------------
//
CLogExampleLogDatabaseObserver::~CLogExampleLogDatabaseObserver()
	{
	Cancel();
	delete iLogClient;
	iFs.Close();
	}

// ----------------------------------------------------
// CLogExampleLogDatabaseObserver::NewL(MDatabaseObserver& aObserver)
// Symbian 2-phase constructor
// ----------------------------------------------------
//
CLogExampleLogDatabaseObserver* CLogExampleLogDatabaseObserver
			::NewL(MDatabaseObserver& aObserver)
	{
	CLogExampleLogDatabaseObserver* self = CLogExampleLogDatabaseObserver
											::NewLC(aObserver);
	CleanupStack::Pop(self);
	return self;
	}

// ----------------------------------------------------
// CLogExampleLogDatabaseObserver::NewLC( MDatabaseObserver& aObserver)
// Symbian 2-phase constructor
// ----------------------------------------------------
//
CLogExampleLogDatabaseObserver* CLogExampleLogDatabaseObserver
			::NewLC(MDatabaseObserver& aObserver)
	{
	CLogExampleLogDatabaseObserver* self = new (ELeave) CLogExampleLogDatabaseObserver( aObserver );
	CleanupStack::PushL(self);
	self->ConstructL(aObserver);
	return self;
	}

//======================= PRIVATE ====================== 

// ----------------------------------------------------
// CLogExampleLogDatabaseObserver::ConstructL(MDatabaseObserver& aObserver)
// Symbian 2-phase constructor
// ----------------------------------------------------
//
void CLogExampleLogDatabaseObserver::ConstructL(MDatabaseObserver& aObserver)
	{

	User::LeaveIfError(iFs.Connect());
	
	//establish connection to log engine
	iLogClient = CLogClient::NewL(iFs);
 	
 	iObserver = aObserver;
	CActiveScheduler::Add(this);
	
	}

// ----------------------------------------------------
// CLogExampleLogDatabaseObserver::RunL()
// RunL for active object
// ----------------------------------------------------
//
void CLogExampleLogDatabaseObserver::RunL()
	{

	if(iStatus != KErrNone )
		{
		iObserver.NotifyChangeL();
		NotifyChange(); // Set this observer again
		}
	}
	
// ----------------------------------------------------
// CLogExampleLogDatabaseObserver::DoCancel()
// Notifies client to cancel
// ----------------------------------------------------
//
void CLogExampleLogDatabaseObserver::DoCancel()
	{
	iLogClient->NotifyChangeCancel();
	}

// ----------------------------------------------------
// CLogExampleLogDatabaseObserver::NotifyChange()
// Notifies client of change
// ----------------------------------------------------
//
void CLogExampleLogDatabaseObserver::NotifyChange()
	{
	if(IsActive())
		{
		return;
		}
	iLogClient->NotifyChange(1000000, iStatus);
	SetActive();
	}
	
//End of file
